<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // let a = 1;
      // let b = 2;
      // let c = 3;
      // let [a, b, c] = [1, 2, 3]; //数组的方式
      // console.log(a, b, c);
      // let { mayName: a, myAge: b } = { mayName: "jack", myAge: 20 };
      // console.log(a, b);
      // //混合结构
      // let [{ x }, a, b] = [{ x: 2 }, 111, 222];
      // console.log(a, b, x);
      let [foo1, a, b] = "hello";
      console.log(foo1, a, b);
      // // let [bar] = 123;
      // let [bar2] = true;
      //rest参数 展开运算符 剩余参数
      // let [a, b, ...c] = [1, 2, 3, 4, 5, 6];
      // console.log(a);
      // console.log(b);
      // console.log(c);

      function foo(a, b, ...c) {
        console.log(c);
        console.log(foo.length); //不包括rest参数
      }
      foo(1, 2, 3, 4, 5);

      // 不定参数（rest 参数 ...）
      function add(...values) {
        let sum = 0;
        for (var val of values) {
          sum += val;
        }
        return sum;
      }
      add(2, 5, 3); // 10

      //假设一个函数可以传入任意个num，返回所有num相加的值
      function foot(){
				var result=0;
				for(var i=0;i<arguments.length;i++){
					result+=arguments[i];
					console.log(arguments[0]);
				}
				console.log(arguments[arguments.length-1]);
				console.log("所有实参累加的结果求和是："+result);
			}
			foot(1,2,3);
    </script>
  </body>
</html>
